<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}/">
		<title>广告管理</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<style type="text/css">
		.actived{color:red;}
		</style>
		
		<%@ include file="/WEB-INF/jspf/statics.jspf"%>
	</head>
<body>
		<%@include file="/WEB-INF/pages/common/header.jsp" %>
		<%@include file="/WEB-INF/pages/common/menu.jsp" %>
		<div id="rightqqqq" style="border-left-style:groove ;float:left;width:88%;height:10px;padding-left:4px;min-height:80%;overflow-y:auto; overflow-x:hidden; ">
           <div style="margin-top:10px;height:auto;">
			 <div id="navContainer" class="navC mb10">  
		        <ul>  
		            <li class="current"><a onclick="advertiseList();" hidefocus="true">广告管理</a></li>  
		            <li><a  onclick="addAdvertise();" hidefocus="true">广告添加</a></li>  
		        </ul>  
   			 </div>  
			</div>
			<div style="float: left; width: 99%; height:auto;">
			<!--div-958 start-->
			<div class="div-958" style="margin-top: 0px; width: 100%;height: 100%;">
				<div style="width: 100%;height: 100%;" class="container clearfix w942">
					<div style="width: 100%;" class="cont bl0">
						<!-- content start -->
						<div class="content">
							<!-- orderResults start -->
							<div class="orderResults" ng-show="orderForm.searchFlag">
							<div class="table-toolbar pusht">
                                    <div class="btn-group right toggle-content">
                                        <a class="" href="#">
                                        	    更改列显示
                                        </a>
                                        <div class="dropdown-menu twin-cols-dropdown-menu" id="column-edit-01"></div>
                                    </div>
                                </div>
								<!-- dataTable_wrapper start -->
								<div id="dataTable_wrapper" class="dataTables_wrapper" role="grid">
									<div class="top">
										<div class="dataTables_info" id="dataTable_info">
											广告列表
										</div>
									</div>
									<table id="dataTable" class="dataTable" name="datatable" aria-describedby="dataTable_info">
										<thead>
                                      <tr role="row">
                                     	 	<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1">广告标题</th>
                                      		<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1">广告描述</th>
                                        	<th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1">广告类型</th>
                                            <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1">启用状态</th>
                                            <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1">添加时间</th>
                                            <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                                        </tbody>
                                    </table>
                                </div>
         
                            </div>
                        </div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<input type="hidden" id="success" onclick="showMessage('success');">
				<input type="hidden" id="fail" onclick="showMessage('fail');">
	</body>
</html>

<script type="text/javascript">
	$().ready(function(){
		$('#navigation').accordion({
			header: '.head',
			navigation1: true, 
			event: 'click',
			autoHeight:true,
			active:0,
			animated: 'bounceslide'
		});
		$("a[class='actived']").removeAttr("class");
		$("#manageAdvertise").attr("class", "actived");
		$("#currentPosition").text("当前位置：票务管理 > 广告管理");
		$("#navContainer li").click(function(){
			$("#navContainer li").each(function(){
				$(this).attr("class","");
			})
			$(this).attr("class","current");
		});
		search();
	});
    function advertiseList(){
    	search();
    }
    
    function addAdvertise(){
    	var str_href = "${ctx}/equipment/update_advertise/add/1";
    	dialog_iframe({url: str_href, title: "添加广告", width: 700, height: 500});
    }
    
    function showMessage(result){
    	if(result=="success"){
    		Showbo.Msg.alert('操作成功!');	
    		search();
    	}else{
    		Showbo.Msg.alert('操作失败!');
    	}
    }
    
    function updateAdvertise(id) {
        var str_href = "${ctx}/equipment/update_advertise/update/"+id;
        dialog_iframe({url: str_href, title: "修改广告", width: 700, height: 500});
    }
     
    function deleteAdvertise(id){
    	Showbo.Msg.confirm("确认删除吗？",function(btn){
    		$.post("${ctx}/equipment/check_exist_invoice_machine",{venueId:id},function(data){
    			if(data=="exist"){
        			Showbo.Msg.alert('该广告正在被使用,请先更该取票机广告引用,再删除该广告!');	
        		}else{
	    			$.post("${ctx}/equipment/delete_advertise",{id:id},function(data){
	            		if(data==1){
	            			Showbo.Msg.alert('删除成功!');	
	            		}else{
	            			Showbo.Msg.alert('删除失败!');
	            		}
	            		search();
	            	});
        		}
    		});
    	});
    }

    function search() {
    	 $(".dropdown-menu").empty();
    	$(".toggle-content").hover(function () {
            $(this).find(".dropdown-menu").show();
        }, function () {
            $(this).find(".dropdown-menu").hide();
        });
        
        $("#dataTable").dataTables({
            "sAjaxSource": "${ctx}/equipment/manage_advertise",
            "fnServerData": function (sSource, aoData, fnCallback) {
             	//var postData = aoData.concat($("#searchForm").serializeArray());
                $.post(sSource,function (json) {
                    fnCallback(json.data);
                }, "json");
            },
            "aoColumns": [
				{
				    "sName": "title", "mDataProp": "title", "bSortable": false
				},
				 {
                    "sName": "advertise_description", "mDataProp": "advertiseDescription", "bSortable": false
                }, 
                {
                    "sName": "advertise_type", "mDataProp": "advertiseTypeName", "bSortable": false
                },
               
                { "mDataProp": function (aData, type, val) {
                        switch (aData.status) {
                            case 1:
                                val = "<span style='color: balck'>已启用</span>";
                                break;
                            case 2:
                                val = "<span style='color: balck'>未启用</span>";
                                break;
                            default:
                            	val="<span style='color: balck'>未启用</span>";
                        }
                        return val;
                    }, "sName": "status", "bSortable": false
                },
                {
                    "sName": "add_time", "mDataProp": "addTimeStr", "bSortable": false
                },
                {
                    "mDataProp": function (aData, type, val) {
                        return val = '<a class="link_detail" onclick="updateAdvertise('+aData.id+')" target="_blank">编辑</a>'+'|&nbsp;<a class="link_detail" onclick="deleteAdvertise('+aData.id+')">删除</a>';
                    }, 
                    "sName": "id", "bSortable": false
                }
            ]
        });
        $("#dataTable").columnManager({"listTargetID": "column-edit-01"});
         $(".bottom").remove();
    }
</script>